include:
  - dos2unix
# Just like in the doc, we need to put this contents into repo
Yum Repo for nginx:
  file.managed:
    - name: /etc/yum.repos.d/nginx.repo
    - contents: |
        [nginx]
        name=nginx repo
        baseurl=http://nginx.org/packages/centos/6/$basearch/
        gpgcheck=0
        enabled=1
# This is the yum install
Install nginx:
  pkg.installed:
    - name: nginx
Setup nginx config:
  file.managed:
    - name: /etc/nginx/nginx.conf
    - source: salt://app/training/files/nginx.conf
    - template: jinja
Enable nginx service:
  service.running:
    - name: nginx
    - enable: True
    - listen:
      - file: /etc/nginx/nginx.conf
#Our custom page:
#  file.managed:
#    - name: /usr/share/nginx/html/{{ salt["pillar.get"]("app:training:page") }}.html 
#    - contents: {{ salt["pillar.get"]("app:training:text") }}

#{% set training = salt["pillar.get"]("app:training") %}
#{% if training["display"] %}
#Our custom page:
#  file.managed:
#    - name: /usr/share/nginx/html/{{ training["page"] }}.html
#    - source: salt://app/training/files/template.html.jinjia
#    - template: jinja
#{% else %}
#  #Remove the file
#  file.absent:
#    - name: /usr/share/nginx/html/{{ training["page"] }}.html
#{% endif %}


{% for app_env in ["local", "dev", "stage"] %}
Create dummy page for {{ app_env }} env:
  file.managed:
    - name: /usr/share/nginx/html/{{ app_env }}/index.html
    - contents: This is a page for {{ app_env }}
    - makedirs: True
{% endfor %}
